import numpy as np

dt = [('IQ','i2'),('Height','f4'),('Age','i2'),
      ('Rating','f4'),('College','U30')]

team_a = np.loadtxt(r'D:\ui\next_level\Numpy_high\data\team.txt',dt,delimiter=',')

iq_a = team_a['IQ']
ht_a = team_a['Height']
age_a = team_a['Age']
rate_a = team_a['Rating']

# 皮尔逊相关系数（看一个数和另一个数有无关系）
relation = np.corrcoef(iq_a,ht_a)[0,1]  # 它是一个2x2的数组，要将其转为单个数字，可使用索引[0,1]或[1,0]

# 如果想将 Rating范围从 0.0 ~ 5.0 变为 0.0 ~ 10.0 可通过将整列乘2来实现
team_a['Rating'] *= 2  # 每个值会被 乘2

# 还可以随时使用 np.append 函数为数组附加新的数据行
new_a = np.array((100,70,18,5.5,'C.C.C'),dtype=dt)
team_a = np.append(new_a)


# 文件写入
fmt_str = '%i,%.1f,%i,%.1f,%s'
np.savetxt('team_datas.text',team_a,fmt=fmt_str,newline='\n')

